<template>
	<view>
		<view class="status_bar"></view>
		
		<!-- 推荐轮播列表 -->
		<swiper class="card-swiper" :class="dotStyle?'square-dot':'round-dot'" :indicator-dots="true" :circular="true" :autoplay="true" interval="5000" duration="500" @change="cardSwiper" indicator-color="#8799a3" indicator-active-color="#0081ff">
			<swiper-item v-for="(item,index) in bannerArr" :key="index" :class="cardCur==index?'cur':''">
				<view class="swiper-item">
					<image :src="imgPath + item.imgUrl" mode="aspectFill"></image>
				</view>
			</swiper-item>
		</swiper>
		
		<!-- 全部图集列表 -->
		<view>
			<scroll-view class="atlas-list" :id="scrollId" :scroll-y="isScroll" @scroll="scroll" @scrolltolower="scrolltolower">
				<view v-for="item in atlasArr" class="atlas-image">
					<lazy-load
							:key="imgPath + item.imgUrl"
							:src="imgPath + item.imgUrl"
							:content="content"
							:atlasId="item.id"
							:scroll-id="'#'+scrollId"
							@controlRoll="controlRoll"
							mode="aspectFill"></lazy-load>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import lazyLoad from '../../components/lazyLoad/index';
	import lazyLoadPlugin from '../../plugins/lazyLoad/js/index';
	export default {
		data() {
			return {
				imgPath:this.imgPath,
				
				cardCur: 0,
				dotStyle: false,
				bannerArr:[],
				
				scrollId: "scroll",
				atlasArr:[],
				isScroll:true,
				content:[
					{
						text:'反馈',
						status:1
					},{
						text:'收藏',
						status:2
					}
				]
			}
		},
		onLoad() {
			// 推荐轮播
			this.bannerList();
			// 图集列表
			this.atlasList();
		},
		onShow() {
		},
		/**
		 * @author smallfour
		 * @description 分享好友
		 */
		onShareAppMessage(res){
			return {
				title:'四叶图集',
				imageUrl:'http://image.hermit.love/IMG_3494.JPG',
				path:'/pages/tabBar/index'
			}
		},
		/**
		 * @author smallfour
		 * @description 分享朋友圈
		 */
		onShareTimeline(){
			return {
				title:'四叶图集',
				imageUrl:'http://image.hermit.love/IMG_3494.JPG',
				path:'/pages/tabBar/index'
			}
		},
		methods: {
			controlRoll:function(){
				this.isScroll = this.isScroll ? false : true
			},
			// 推荐轮播
			bannerList:function(){
				this.$api.bannerList({}).then(res => {
					this.bannerArr = res.data;
				}).catch(err => {
					console.log(err);
				})
			},
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},
			scroll () {
				lazyLoadPlugin.scroll();
			},
			// 滚动置底
			scrolltolower(){
				this.atlasList();
			},
			// 图集列表
			atlasList:function(){
				this.$api.atlasList({}).then(res => {
					this.atlasArr = this.atlasArr.concat(res.data);
					// console.log(this.atlasArr);
					lazyLoadPlugin.init({
					    id: '#scroll'
					});
				}).catch(err => {
					console.log(err);
				})
			}
		},
		mounted () {
		    // lazyLoadPlugin.init({
		    //     id: '#scroll'
		    // });
		},
		components: {
		    lazyLoad
		},
		destroyed () {
		    lazyLoadPlugin.destroy();
		},
		// onReachBottom(){
		// 	this.atlasList();
		// }
	}
</script>

<style lang="scss">
	.status_bar {
		height: var(--status-bar-height);  
		width: 100%;
	}
	// 轮播
	.swiper{
		overflow: hidden;
		height: 480rpx;
		image{
			width: 100%;
			height: 480rpx;
		}
	}
	.atlas-list{
		display: flex;
		flex-wrap:wrap;
        align-items: start;
		.atlas-image{
			width:50%;
			// width: calc(50% - 30rpx);
			margin-top: 30rpx;
			display: inline-block;
			// image{
			// 	width: 100%;
			// 	height: 240rpx;
			// 	display: block;
			// 	border: 4rpx solid #000;
			// 	border-radius: 8rpx;
			// }
		}
		.atlas-image:nth-child(odd){
			padding: 0 10rpx 0 20rpx;
		}
		.atlas-image:nth-child(even){
			padding: 0 20rpx 0 10rpx;
		}
	}

    #scroll {
        // background: #e8e8e8;
        height: calc(100vh - 480rpx);
        // height:100vh;
    }
	.component-img-lazyload {
	    box-shadow: 0 2upx 12upx rgba(0, 0, 0, 0.2);
	    background: #fff;
	    // min-width: calc(50% - 160upx);
	    min-height: 240upx;
	    // padding: 40upx;
	    // margin: 40upx;
	    border-radius: 20upx;
		line-height: 0;
	
	    /deep/ .img {
	        width: 100%;
			height: 240rpx;
	        border-radius: 14upx;
	    }
	}
</style>
